﻿@{
    ViewData["Title"] = "文章管理";
    ViewData["BreadCrumb"] = "主页 / 文章管理";
}

@section toolbar{
    <form asp-action="List" method="post">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" id="title" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                @*<button class="layui-btn layuiadmin-btn-forum-list" lay-submit="" lay-filter="LAY-app-forumlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>*@
                <a class="layui-btn layuiadmin-btn-forum-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i></a>
            </div>
        </div>
    </form>
}
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加文章</button>
        <button class="layui-btn layui-btn-sm" lay-event="huangdi">录入黄帝内经</button>
        <button class="layui-btn layui-btn-sm" lay-event="oneindex">一键索引</button>
    </div>
</script>
<table class="layui-hide" id="myTable" lay-filter="myTable" lay-even=""></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
    <a class="layui-btn layui-btn-xs" lay-event="static">静态化</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
@section scripts{

    <script>
        layui.config({
            version: "3.0.0"
            , base: '@Url.Content("~/res/mods/")'
        }).extend({
            fly: 'index'
            }).use(['fly', 'table'], function () {
                var table = layui.table
                    , $ = layui.$
                    , fly = layui.fly;

                $("#search").click(function () {
                    table.reload('myTable', {
                        url:'@Url.Content("~/Article/List")'
                        ,where: { //设定异步数据接口的额外参数，任意设
                            title: $("#title").val()
                            //…
                        }
                        , page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    }); //只重载数据
                });


                //第一个实例
                table.render({
                    elem: '#myTable'
                    , url: '@Url.Content("~/Article/List")' //数据接口
                    , method: 'post'
                    , page: true //开启分页
                    , limit: 10
                    , cellMinWidth: 150
                    , toolbar: '#toolbarDemo'
                    , title: '数据列表'
                    , cols: [[ //表头
                          { field: 'id', title: 'ID', sort: true,width: 80 }
                        , { field: 'title', title: '标题', sort: true, width: 150 }
                        , { field: 'channelName', title: '频道', sort: true, width: 150 }
                        , { field: 'staticPath', title: '静态地址', sort: true }
                        , { field: 'supportCount', title: '支持次数', sort: true }
                        , { field: 'userName', title: '创建用户', sort: true }
                        , { field: 'createDateTime', title: '创建时间', sort: true }
                        , { field: 'isFirst', title: '是否置顶', sort: true }
                        , { field: 'isVisible', title: '是否显示', sort: true }
                        , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 230 }
                    ]]
                });
                //头工具栏事件
                table.on('toolbar(myTable)', function (obj) {
                    console.log(obj);
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'add':
                            location.href = '@Url.Content("~/Article/Add")';
                            break;
                        case 'huangdi':
                            {
                                layer.confirm('确定录入黄帝内经？', function (index) {
                                    var loading = layer.load(0, {
                                        shade: true
                                    });
                                    fly.json('@Url.Content("~/Article/AddHuangDi")', function (res) {
                                        layer.close(loading);
                                        layer.msg(res.msg);
                                    });
                                    //window.location.reload();
                                    window.location = window.location;
                                });
                            } break;
                        case 'oneindex':
                            {
                                layer.confirm('确定一键全部索引？', function (index) {
                                    var loading = layer.load(1, {
                                        shade: true
                                    });
                                    fly.json('@Url.Content("~/Article/OneIndex")', function (res) {
                                        layer.msg(res.msg);
                                    });
                                    layer.close(loading);
                                });
                            } break;
                    };
                });
                //监听行工具事件
                table.on('tool(myTable)', function (obj) {
                    var data = obj.data;
                    //console.log(obj)
                    switch (obj.event) {
                        //审核
                        case 'check':
                            {
                                layer.confirm('确定审核通过？', function (index) {
                                    fly.json('@Url.Content("~/Article/Check")', { 'id': data.id }, function (res) {
                                        layer.msg(res.msg);
                                    });
                                    //window.location.reload();
                                    window.location = window.location;
                                });
                            } break;
                        case 'static':
                            layer.msg("静态化成功");
                            break;
                        //编辑
                        case 'edit':
                            {
                                location.href = '@Url.Content("~/Article/Edit/")'+data.id;
                            } break;
                        //删除
                        case 'del':
                            {
                                layer.confirm('真的删除行么', function (index) {
                                    fly.json('@Url.Content("~/Article/Del")', { 'id': data.id }, function (res) {
                                        layer.msg(res.msg);
                                        });
                                    obj.del();
                                    layer.close(index);
                                });
                            } break;

                    }

                    @*if (obj.event === 'del') {
                        layer.confirm('真的删除行么', function (index) {
                            fly.json('/Admin/Home/RequestArticles', { 'action': 'delete', 'data': JSON.stringify(data) }, function (res) {
                                layer.msg(res.msg);
                            });
                            obj.del();
                            layer.close(index);
                        });
                    } else if (obj.event === 'edit') {
                        layer.prompt({
                            formType: 2
                            , value: data.email
                        }, function (value, index) {
                            obj.update({
                                email: value
                            });
                            layer.close(index);
                        });
                    } else if (obj.event === "addPermission") {
                        layer.open({
                            type:2
                            ,title: '添加权限'
                            ,area: ['800px', '600px']
                            ,content: ['@Url.Content($"~/Role/AddPermission?roleId=")'+data.id]
                        });

                    }*@
                });

        });
    </script>

}